package JiHeDemo.mygenneric;

/**
 * T  占位符，表示一种引用类型，使用多个用逗号隔开
 *
 * @author 86150
 */
class TestGeneric {
	public static void main(String[] args) {
		MyGeneric<String> mg1 = new MyGeneric("hello world");
		mg1.show("你好，我是字符串");
		System.out.println(mg1.getT());
		MyGeneric<Integer> mg2 = new MyGeneric(10);
		mg2.show();
		System.out.println(mg2);
		MyGeneric<String> mg3 = mg1;

	}

}

public class MyGeneric<T> {
	T t;

	public MyGeneric(T t) {
		this.t = t;
	}

	public MyGeneric() {
	}

	@Override
	public String toString() {
		return "MyGeneric{" +
				"t=" + t +
				'}';
	}

	//添加到方法参数
	public void show(T t) {
		System.out.println(t);
	}

	public void show() {
		System.out.println(this.t);
	}

	//使用泛型作为方法的返回值
	public T getT() {
		return t;
	}
}
